package pkgjeudestrategie.ressource;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import pkgjeudestrategie.Zoomable;

/**
 *
 * @author Marvens
 */
public abstract class Ressource extends Zoomable {
    
    //argent est une variabe temporaire 
static int argent =0;
    int level = 0;
    int position;
    int x;
    int y;
    static int coutNv1;
    static int coutNv2;
    static int coutNv3;
    static int coutNv4;
    static int coutNv5;
    static int revenuNv1;
    static int revenuNv2;
    static int revenuNv3;
    static int revenuNv4;
    static int revenuNv5;
    int upgradeInProgress=0;
    boolean upgradable = true;
    boolean isActivated;

    public Ressource(int position) {
        this.position = position;
        setSize(400, 400);
    }
    public static String getDescription(int type, int i){
    String s="";
    if(type==0){
        if(i==0){s="Produit du bois: "+argent;}
        else if(i==1){s="Exploitation de bois";}
    }
    else if(type==1){
        if(i==0){s="Produit de l'argent: "+argent;}
        else if(i==1){s="Mine d'argent";}
    }
    else if(type==2){
        if(i==0){s="Produit des diamants: "+argent;}
        else if(i==1){s="Mine de diamants";}
    }
    else if(type==3){
       if(i==0){ s="Produit de l'or: "+argent;}
        else if(i==1){s="Minne d'or";};
        
    }
    else if(type==4){
       if(i==0){ s="Produit des minerais quelconques (fer,cuivre,zinc,etc.): "+argent;}
        else if(i==1){s="Mine de minerai";}
        
    
    }
    if(i==0){
        if(s.length()>31) {s=s.substring(0,30)+"\n"+s.substring(30);}
       if(s.length()>61) {s=s.substring(0,60)+"\n"+s.substring(60);}
        if(s.length()>91) {s=s.substring(0,90)+"\n"+s.substring(90);}
        if(s.length()>121) {s=s.substring(0,120)+"\n"+s.substring(120);}
    }
    return s;
}
   abstract public int getTypeInt();
    public abstract int getCout(boolean b);
    public void setPosition() {
        if (position == 1) {
            x = 0;
            y = 0;
        } else if (position == 2) {
            x = (int) (getWidth() / 2);
            y = 0;

        } else if (position == 3) {
            x = 0;
            y = (int) (getWidth() / 2);

        } else if (position == 4) {
            x = (int) (getWidth() / 2);
            y = (int) (getWidth() / 2);

        }
    }

    public boolean isUpgradable() {
        if (level >= 3) {
            return false;
        }

        return true;


    }

    public int getLevel() {
        return level;
    }

    public void activateConstruction(){
        
        isActivated=true;
        upgradeInProgress=0;
    }
    public boolean isActivated(){
        return isActivated;
    }
public void levelUp() {
        if(isActivated){
        if(upgradeInProgress==requiredTime()){
           level++;
        isActivated=false;
        }
        else{
          upgradeInProgress++;  
        }}
    }
    public int requiredTime(){
        //i doit correspondre au nombre de joueurs...
        int i=-1;
        int playerListSize=2;
        if(level == 0){
            i=playerListSize;
            }
            else if (level == 1) {
            i=2*playerListSize;
                
        } else if (level == 2) {
            i=3*playerListSize;
            
        } 
        return i;
    }
    @Override
    public String toString() {
        return "Ressource";
    }

    
    @Override
    abstract protected void paintComponent(Graphics g);
}
